package com.upic.serviceImpl;

import com.upic.po.Clazz;
import com.upic.repository.ClazzRepository;
import com.upic.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author YeTian
 * @date 2018/2/7/007
 */
@Service("clazzService")
public class ClazzServiceImpl implements ClazzService {

    @Autowired
    private ClazzRepository clazzRepository;

    @Override
    public Clazz saveClazz(Clazz clazz) {
        return clazzRepository.save(clazz);
    }

    @Override
    public String deleteClazz(long clazzId) {
        clazzRepository.delete(clazzId);
        return "SUCCESS";
    }

    @Override
    public Page<Clazz> searchClazz(Pageable pageable) {
        return clazzRepository.findAll(pageable);
    }

    @Override
    public List<Clazz> searchClazz() {
        return clazzRepository.findAll();
    }

    @Override
    public Clazz findOne(long clazzId) {
        return clazzRepository.findOne(clazzId);
    }

    @Override
    public Clazz updateClazz(Clazz clazz) {
        return clazzRepository.saveAndFlush(clazz);
    }
}
